#!/usr/bin/env bash

###############################
# author: wzq
# version: 0.1
# usage:
###############################

function show_menu {
#    clear
#   printf "%20s %s\n" "Menu1"
    echo
    echo -e "\t\t\tMenu\n"
    echo -e "\t 1. mvn clean package"
    echo -e "\t 2. mock data"
    echo -e "\t 3. build docker image"
    echo -e "\t 4. me_git_tag"
    echo -e "\t 5. git statics"
    echo -e "\t 6. git add -> commit -> push"
    echo -e "\t 7. mvn spring-boot:run"
    echo -e "\t q. Exit program\n\n"
    echo -en "\t\tEnter option(default 1): "
    read -n 1 option
    option=${option:-1}
}


function mvn_package {
    mvn clean package -Dmaven.test.skip=true
}

function test_one_module {
#    mvn test -DfailIfNoTests=false -Dtest=testname -pl subproject
    mvn test -DfailIfNoTests=false -pl subproject
}

function me_git_add_commit_push {
    read -p "git commit message:" msg
    if [ -z "$msg" ]; then
        msg="by wzq"
    fi
    git add -A && git commit -m "$msg" && git push
}

function me_git_tag {
    for t in `git tag -l`; do
        git cat-file -p `git rev-parse $t` \
        | grep -v -e "^object\|^type\|^tagger\|^$\|^tree\|^parent\|^author\|^committer\|^by\|^$" \
        | sed '/./ {N; s/\n/ /;}'
    done
}

clear
while [ 1 ] ; do
    cd `dirname $0`
    show_menu
    echo
    case $option in
        1) mvn clean package -Dmaven.test.skip=true ;;
        2) ./script/mock_data.sh ;;
        3) echo "TODO" ;;
        4) me_git_tag ;;
        5) ./script/statics.sh ;;
        6) me_git_add_commit_push ;;
        q) exit ;;
        *) echo "Sorry, wrong selection" ;;
    esac
done
